import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            friendss: {
                offset: 0,
                length: 25,
                items: [{
                    id: '',
                    doctor_id: '',
                    member_id: '',
                    member_name: '',
                    type: '',
                }]
            },
        };
        return this.state;
    },
    listFriends() {
        var me = this;
        var data = {offset: me.state.friendss.offset, length: me.state.friendss.length};
        var flag = true;
        if(me.beforeListFriends) {
            flag = me.beforeListFriends(data);
        }
        if(flag) {
            app.get("api/doctor_contacts/list", data, function(res) {
                var data = [];
                for(var i = 0; i < res.data.result.data.length; i++) {
                    var m = {
                        id: res.data.result.data[i].id,
                        doctor_id: res.data.result.data[i].doctor_id,
                        member_id: res.data.result.data[i].member_id,
                        member_name: res.data.result.data[i].member_name,
                        type: res.data.result.data[i].type,
                    }
                    data.push(m);
                }
                me.setState({friendss:{offset: me.state.friendss.offset + me.state.friendss.length, length: me.friendss.length, items: data}});
                if(me.afterListFriends) {
                    me.afterListFriends(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
